<template>
    <el-select v-model="selectedVal" :clearable="!form" class="filter-item" placeholder="商城权益方案" style="width: 150px;">
        <el-option label="未选择" :value="0" v-if="form"></el-option>
        <el-option
            v-for="(item, index) in mallWithdraws"
            :key="index"
            :label="item.id + ' ) ' + item.name"
            :value="item.id">
        </el-option>
    </el-select>
</template>

<script>
export default {
    props: {
        value: {

        },
        form: {
            type: Boolean,
            default: false,
        }
    },
    data () {
        return {
            selectedVal: '',
        };
    },
    computed: {
        mallWithdraws () {
            return this.$store.state.mallWithdraw.all;
        },
    },
    watch: {
        value() {
            this.syncForm();
        },
        selectedVal() {
            this.$emit('input', this.selectedVal);
        }
    },
    methods: {
        getAll() {
            if (!this.mallWithdraws.length) this.$store.dispatch('mallWithdraw/All', 'mallWithdraw');
        },
        syncForm() {
            this.selectedVal = this.value || (this.form ? 0 : '');
        },
    },
    created() {
        this.getAll();
        this.syncForm();
    }
}
</script>

<style scoped>

</style>
